jQuery(function()
    {
        jQuery("input[name='statisticsType']").click(function()
        { 
        	jQuery("input[name='startDate'],input[name='endDate']").val("");
        	jQuery("input[name='startDate'],input[name='endDate']").unbind("click");
        	var startDate=jQuery("input[name='startDate']").clone(false).click(showqueryDate);
          	jQuery("input[name='startDate']").remove();
        	jQuery(startDate).appendTo("#startDateDiv");
           	var endDate=jQuery("input[name='endDate']").clone(false).click(showqueryDate);
          	jQuery("input[name='endDate']").remove();
        	jQuery("input[name='endDate']").remove();
        	jQuery(endDate).appendTo("#endDateDiv");  
        }		
        );
        $('input[name="statisticsType"]:checked').trigger("click");
        var now = new Date();
        var startDate =DateUtil.dateAdd('d',-7,now);
        jQuery("#startDate").val(DateUtil.dateToStr('yyyyMMdd',startDate));
        jQuery("#endDate").val(DateUtil.dateToStr('yyyyMMdd',now));
        queryPlatForm(1, 15);
    }
	);


function queryPlatForm(pageIndex,pageSize)
{
	  var startDate =jQuery("#startDate").val();
	  var endDate=jQuery("#endDate").val();
	  if(!startDate)
	  {
		 jQuery("#startDate").select();
		 return alert("查询开始日期不能为空!");  
	  }
	  if(!endDate)
	  {
		  jQuery("#endDate").select();
		  return alert("查询结束日期不能为空!");  
      }
	  var displayType = $('input[name="displayType"]:checked').val();
	  if(displayType=="grid")
	  {
		  var url =base+"/platformProfitanloss/platformProfitanloss.do?pageIndex="+pageIndex+"&pageSize="+pageSize;
	      var params =jQuery("#queryForm").serialize();
	      params=decodeURIComponent(params,true); 
	      jQuery("#profitanlossContent").load(url+"&"+ encodeURI(encodeURI(params))); 
	  }
	  else
	  {
		  var url =base+"/platformProfitanloss/platformProfitanlossChart.do?date="+new Date().getTime();
	      var params =jQuery("#queryForm").serialize();
	      params=decodeURIComponent(params,true);  
	      jQuery("#profitanlossContent").load(url,function()
	      {
	    	    jQuery.post(
	    	    		  base+"/platformProfitanloss/platformProfitanlossChartData.do?"+ encodeURI(encodeURI(params)), 
	                      function(result){
	                           initLineChart(result);
	                });
	      }	  
	      ); 
	  }
     
}


function initLineChart(data)
{
    $('#chartDiv').highcharts({
        chart: {
            type: 'line',
            backgroundColor:'#f3ffe3'
        },
        credits:{enabled:false},
        exporting:{enabled:false},
        title: {
            text: '平台盈亏统计'
        },
        subtitle: {
            text: data.subtitle
        },
        xAxis: {
            categories: data.categories
        },
        yAxis: {
            title: {
                text: '金额 (RMB)'
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            } 
        }, 
        series: data.series
    });
}

function showqueryDate()
{ 
	var statisticsType = $('input[name="statisticsType"]:checked').attr("fmt");
	new WdatePicker({dateFmt:statisticsType});
}

 